package com.changhai.diabetes.action;

import com.changhai.diabetes.model.Bear;
import com.changhai.diabetes.model.OpertResultMsg;
import com.changhai.diabetes.service.BearService;

/**
 * 生育史
 * 
 * @author Andy
 * 
 */
public class BearAction extends BaseAction {

	private static final long serialVersionUID = 4392936553263004630L;
	private OpertResultMsg opertMsg;
	private Long patientid;
	private Bear bear;
	private BearService bearService;
	private Integer flag = 0;
	
	public String execute() throws Exception {
		return super.execute();
	}

	public String query() {
		return "input";
	}

	public String insertNewBear(){
		bear.setPatientid(patientid);
		tbList = this.getTableForEnter(patientid,flag); 
		return "input";
	}
	
	public String editBear(){
		if (patientid != null && patientid > 0) {
			try {
				bear = bearService.searchByPatientId(patientid);	
				tbList = this.getTableForEnter(patientid,flag);
			} catch (Exception e) {
				e.printStackTrace();
				opertMsg = new OpertResultMsg(Long.valueOf(1), "暂无生育史信息!");
			}
			return "input";
		} else {
			return "query";
		}
	}
	
	public String saveEditBear(){
		if (patientid == null || patientid <= 0 || bear == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				bearService.saveEditBear(bear);
				this.setFlag(1);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("update", "生育史", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editBear();
	}
	
	public String saveNewBear(){
		if (patientid == null || patientid <= 0 || bear == null) {
			opertMsg = new OpertResultMsg(Long.valueOf(1), "参数错误!");
		} else {
			try {
				bearService.saveNewBear(bear);
				opertMsg = new OpertResultMsg(Long.valueOf(0), "保存成功!");
				commonService.writeLogToFile("insert", "生育史", patientid);
			} catch (Exception e) {
				opertMsg = new OpertResultMsg(Long.valueOf(1), "保存失败!");
			}
		}
		return this.editBear();
	}
	
	public OpertResultMsg getOpertMsg() {
		return opertMsg;
	}

	public void setOpertMsg(OpertResultMsg opertMsg) {
		this.opertMsg = opertMsg;
	}

	public Long getPatientid() {
		return patientid;
	}

	public void setPatientid(Long patientid) {
		this.patientid = patientid;
	}

	public Bear getBear() {
		return bear;
	}

	public void setBear(Bear bear) {
		this.bear = bear;
	}

	public BearService getBearService() {
		return bearService;
	}

	public void setBearService(BearService bearService) {
		this.bearService = bearService;
	}

	public Integer getFlag() {
		return flag;
	}

	public void setFlag(Integer flag) {
		this.flag = flag;
	}
}
